home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / doors_1 / doorskl3.zip / ANSI.ASM next >
Assembly Source File  |  1991-12-15  |  13KB  |  390 lines

  1. ; this is ripped off from pd code in RBBS-ASM (was ANSI1-7.ASM)
  2. ; has been heavily modified by M. Kimes, who isn't much of an
  3. ; asm-programmer.  Now works with C in a strange way and supports
  4. ; configurable window.  It's momma wouldn't know it now (and probably
  5. ; would claim it's the type of program she warned it about).
  6. ; I reckon it was public domain before, and still is.
  7. ;
  8. ; int  far pascal ansi      (char far *str);
  9. ; void far pascal setcoords (int topx,int topy,int botx,int boty);
  10. ; void far pascal getcoords (int far *topx,int far *topy,int far *botx,int far *boty);
  11. ;
  12.  
  13. .model large
  14.  
  15. ANSI_PRNT SEGMENT PUBLIC 'CODE'
  16.           ASSUME CS:ANSI_PRNT
  17.           PUBLIC ANSI,SETCOORDS,GETCOORDS,SETFASTANSI
  18.           PUBLIC _atop,_atopy,_atopx,_abot,_aboty,_abotx
  19.  
  20. VID_PAGE          DB 0                  ;Active video page
  21. _atop             LABEL WORD
  22. _atopy            DB 0                  ;top y coord
  23. _atopx            DB 0                  ;top x coord
  24. _abot             LABEL WORD
  25. _aboty            DB 17h                ;bottom y coord
  26. _abotx            DB 4Fh                ;bottom x coord
  27. _fastansiout      DB 1                  ;fast ansi writes?
  28.  
  29.  
  30. GETCOORDS PROC    FAR   ;void pascal far getcoords(int *topx,int *topy,
  31.                         ;                          int *botx,int *boty);
  32.  
  33. ; get window coordinates (0 based)
  34.  
  35.           PUSH    BP
  36.           MOV      BP,SP
  37.           PUSH    DS
  38.           MOV     AH,0
  39.           MOV     AL,_atopx
  40.           MOV     BX,[BP]+18
  41.           MOV     DS,[BP]+20
  42.           MOV     [BX],AX
  43.           MOV     AL,_atopy
  44.           MOV     DS,[BP]+16
  45.           MOV     BX,[BP]+14
  46.           MOV     [BX],AX
  47.           MOV     AL,_abotx
  48.           MOV     DS,[BP]+12
  49.           MOV     BX,[BP]+10
  50.           MOV     [BX],AX
  51.           MOV     AL,_aboty
  52.           MOV     DS,[BP]+8
  53.           MOV     BX,[BP]+6
  54.           MOV     [BX],AX
  55.           POP     DS
  56.           POP      BP
  57.           RET     16
  58.  
  59. GETCOORDS ENDP
  60.  
  61. SETCOORDS PROC    FAR   ;void pascal far setcoords(int topx,int topy,
  62.                         ;                          int botx,int boty);
  63.  
  64. ; set window coordinates (0 based)
  65.  
  66.           PUSH    BP
  67.           MOV      BP,SP
  68.           MOV     AH,[BP]+12
  69.           MOV     _atopx,AH
  70.           MOV     AH,[BP]+10
  71.           MOV     _atopy,AH
  72.           MOV     AH,[BP]+8
  73.           MOV     _abotx,AH
  74.           MOV     AH,[BP]+6
  75.           MOV     _aboty,AH
  76.           POP      BP
  77.           RET     8
  78.  
  79. SETCOORDS ENDP
  80.  
  81.  
  82.  
  83. SETFASTANSI PROC    FAR   ;void pascal far setfastansi(int fast);
  84.  
  85. ; set fast ansi (0 = off)
  86.  
  87.           PUSH    BP
  88.           MOV      BP,SP
  89.           MOV     AH,[BP]+6
  90.           MOV     _fastansiout,AH
  91.           POP      BP
  92.           RET     2
  93.  
  94. SETFASTANSI ENDP
  95.  
  96.  
  97.  
  98. ANSI      PROC    FAR   ;int pascal far ansi(char far *str);
  99.  
  100. ; display a string through DOS' ANSI driver, respecting a window
  101.  
  102.           PUSH    BP                    ;set up stack frame
  103.           MOV     BP,SP
  104.  
  105.           PUSH    DS                    ;save ds
  106.  
  107.           MOV     AH,15                 ;get current video state
  108.           INT     10H
  109.           MOV     VID_PAGE,BH           ;save it
  110.  
  111.           MOV     BX,[BP]+6             ;get string address
  112.           MOV     DS,[BP]+8             ;set ds
  113.           PUSH    BX                    ;save original address
  114.           MOV     CX,BX
  115.           XOR     AX,AX
  116.  
  117. ALOOP:
  118.           CALL    DOCHECKPOS
  119.           MOV     AL,[BX]               ;set dl to char to print
  120.           CMP     AL,27                 ;escape?
  121.           JNZ     GOON                  ;no, skip all this...
  122.           CMP     BYTE PTR [BX]+1,'['   ; check for various ansi
  123.           JNZ     GOON                  ; commands that would screw
  124.           CMP     BYTE PTR [BX]+2,'2'   ; up our window
  125.           JNZ     GOON1                 ; \x1b[2J
  126.           CMP     BYTE PTR [BX]+3,'J'
  127.           JNZ     GOON2
  128.           ADD     BX,4
  129.           CALL    CLEARSCRN
  130.           JMP     ALOOP
  131. GOON1:
  132.           CMP     BYTE PTR [BX]+2,'K'   ; \x1b[K
  133.           JNZ     GOON3
  134.           ADD     BX,3
  135.           CALL    CLEARLINE
  136.           JMP     ALOOP
  137. GOON3:
  138.           CMP     BYTE PTR [BX]+2,'k'   ;\x1b[k
  139.           JNZ     GOON
  140.           ADD     BX,3
  141.           CALL    CLEAREOL
  142.           JMP     ALOOP
  143. GOON2:
  144.           CMP     BYTE PTR [BX]+3,'j'   ;\x1b[2j
  145.           JNZ     GOON
  146.           ADD     BX,4
  147.           CALL    CLEAREOS
  148.           JMP     ALOOP
  149. GOON:
  150.           CMP     AL,0              ;End of string?
  151.           JNZ     NOEXIT1
  152.           JMP     SHORT EXIT1
  153. NOEXIT1:                            
  154.           CMP     _fastansiout,0    ;fast ansi writes?
  155.           JZ      SLOWWRITES        ;nope
  156.           INT     29H
  157.           JMP     SHORT SKIPSLOW
  158. SLOWWRITES:
  159.           MOV     DX,AX
  160.           MOV     AH,2
  161.           INT     21H               ;display it
  162. SKIPSLOW:
  163.           INC     BX
  164.           CMP     BYTE PTR [BX],0   ;end of string?
  165.           JZ      EXIT1             ;yep
  166.           CMP     BX,CX             ;string too long?
  167.           JZ      EXIT1             ;yep, it wrapped; avoid crash
  168.           JMP     ALOOP             ;nope
  169. EXIT1:                              ;wrap it up...
  170.           CALL    DOCHECKPOS
  171.           POP     AX                ;retrieve old start pos
  172.           SUB     BX,AX             ;subtract from current pos
  173.           MOV     AX,BX             ;return length of string printed
  174.  
  175.           POP     DS
  176.           POP     BP
  177.           RET     4
  178.  
  179. ANSI      ENDP
  180.  
  181.  
  182.  
  183. DOCHECKPOS:                         ;check cursor pos, protect window
  184.           PUSH    AX                ;Save the registers that will be affected
  185.           PUSH    BX
  186.           PUSH    CX
  187.           PUSH    DX
  188.           CALL    WHERE_ARE_WE      ; where the cursor is.......
  189. CHECKTOPX:
  190.           CMP     DL,_atopx
  191.           JGE     CHECKBOTX
  192.           MOV     AH,2
  193.           MOV     DL,_atopx
  194.           MOV     BH,VID_PAGE
  195.           INT     10H
  196.           JMP     SHORT CHECKTOPY
  197. CHECKBOTX:
  198.           CMP     DL,_abotx
  199.           JLE     CHECKTOPY
  200.           MOV     DL,_atopx
  201.           INC     DH
  202.           MOV     AH,2
  203.           MOV     BH,VID_PAGE
  204.           INT     10H
  205. CHECKTOPY:
  206.           CMP     DH,_atopy
  207.           JGE     CHECKBOTY
  208.           MOV     AH,2
  209.           MOV     DH,_atopy
  210.           MOV     BH,VID_PAGE
  211.           INT     10H
  212.           JMP     SHORT OUTTAHERE
  213. CHECKBOTY:
  214.           CMP     DH,_aboty         ; Row ???
  215.           JLE     OUTTAHERE         ; Jump if less
  216.           CALL    SCROLLIT          ; else scroll, we're too low
  217.           MOV     DH,_aboty         ; put cursor back in window
  218.           MOV     BH,VID_PAGE
  219.           INT     10H
  220. OUTTAHERE:
  221.           POP     DX                ;Restore registers
  222.           POP     CX
  223.           POP     BX
  224.           POP     AX
  225.           RET
  226.  
  227.  
  228. WHERE_ARE_WE:                       ;Get the current cursor position
  229.           PUSH    AX                ;Save the registers
  230.           PUSH    BX
  231.           PUSH    CX
  232.           MOV     AH,03             ;SET UP FOR ROM-BIOS CALL (03H)
  233.           MOV     BH,VID_PAGE       ;TO READ THE CURRENT CURSOR POSITION
  234.           INT     10H               ; DH = ROW   DL = COLUMN
  235.           POP     CX                ;Restore the registers
  236.           POP     BX
  237.           POP     AX
  238.           RET                        ;And go back from wence we came
  239.  
  240.  
  241. SCROLLIT: PUSH    AX                ;Save the registers that will be affected
  242.           PUSH    BX
  243.           PUSH    CX
  244.           PUSH    DX
  245.           MOV     AH,2              ;Now set cursor position to ???,???
  246.           MOV     DH,_aboty
  247.           MOV     DL,_atopx
  248.           MOV     BH,VID_PAGE       ;attribute
  249.           INT     10H
  250.           MOV     AH,8              ;Get the current character attribute
  251.           MOV     BH,VID_PAGE
  252.           INT     10H
  253.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  254.           MOV     AH,6              ;Otherwise scroll ??? lines
  255.           MOV     AL,1              ;Only blank line ???
  256.           MOV     CH,_atopy
  257.           MOV     CL,_atopx
  258.           MOV     DH,_aboty
  259.           MOV     DL,_abotx
  260.           INT     10H               ;And do it.......
  261.           MOV     AH,2              ;Now set cursor position to ???,???
  262.           MOV     DH,_aboty
  263.           MOV     DL,_atopx
  264.           MOV     BH,VID_PAGE
  265.           INT     10H
  266.           POP     DX                ;Restore the stack like it was
  267.           POP     CX
  268.           POP     BX
  269.           POP     AX
  270.           RET
  271.  
  272. CLEARSCRN:                          ;Clear current window
  273.           PUSH    AX                ;Save the registers
  274.           PUSH    BX
  275.           PUSH    CX
  276.           PUSH    DX
  277.           MOV     AH,2              ;Now set cursor position to ???,???
  278.           MOV     DH,_aboty
  279.           MOV     DL,_atopx
  280.           MOV     BH,VID_PAGE       ;attribute
  281.           INT     10H
  282.           MOV     AH,8              ;Get the current character attribute
  283.           MOV     BH,VID_PAGE
  284.           INT     10H
  285.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  286.           MOV     AH,6              ;Otherwise scroll ??? lines
  287.           MOV     AL,0              ;clear screen
  288.           MOV     CH,_atopy
  289.           MOV     CL,_atopx
  290.           MOV     DH,_aboty
  291.           MOV     DL,_abotx
  292.           INT     10H               ;And do it.......
  293.           MOV     AH,2              ;Now set cursor position to ???,???
  294.           MOV     DH,_atopy
  295.           MOV     DL,_atopx
  296.           MOV     BH,VID_PAGE
  297.           INT     10H
  298.           POP     DX                ;Restore the stack like it was
  299.           POP     CX
  300.           POP     BX
  301.           POP     AX
  302.           RET
  303.  
  304. CLEAREOS:                           ;Clear to end of current window
  305.           PUSH    AX                ;Save the registers
  306.           PUSH    BX
  307.           PUSH    CX
  308.           PUSH    DX
  309.           MOV     AH,8              ;Get the current character attribute
  310.           MOV     BH,VID_PAGE
  311.           INT     10H
  312.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  313.           MOV     AH,6              ;Otherwise scroll ??? lines
  314.           MOV     AL,0              ;clear
  315.           CALL    WHERE_ARE_WE
  316.           PUSH    DX                ;save it
  317.           MOV     CX,DX
  318.           MOV     DH,_aboty
  319.           MOV     DL,_abotx
  320.           INT     10H               ;And do it.......
  321.           MOV     AH,2
  322.           MOV     BH,VID_PAGE
  323.           POP     DX
  324.           INT     10H               ;restore position
  325.           POP     DX                ;Restore the stack like it was
  326.           POP     CX
  327.           POP     BX
  328.           POP     AX
  329.           RET
  330.  
  331. CLEARLINE:                          ;Clear current line
  332.           PUSH    AX                ;Save the registers
  333.           PUSH    BX
  334.           PUSH    CX
  335.           PUSH    DX
  336.           MOV     AH,8              ;Get the current character attribute
  337.           MOV     BH,VID_PAGE
  338.           INT     10H
  339.           CALL    WHERE_ARE_WE
  340.           PUSH    DX                ;save it
  341.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  342.           MOV     AH,6              ;Otherwise scroll ??? lines
  343.           MOV     AL,0              ; clear line
  344.           MOV     CX,DX
  345.           MOV     CL,_atopx
  346.           MOV     DL,_abotx
  347.           INT     10H               ; And do it.......
  348.           MOV     AH,2              ;Now set cursor position to ???,???
  349.           MOV     DL,_atopx
  350.           MOV     BH,VID_PAGE
  351.           INT     10H
  352.           MOV     AH,2
  353.           MOV     BH,VID_PAGE
  354.           POP     DX
  355.           INT     10H               ;restore position
  356.           POP     DX                ;Restore the stack like it was
  357.           POP     CX
  358.           POP     BX
  359.           POP     AX
  360.           RET
  361.  
  362. CLEAREOL:                           ;Clear to end of current line
  363.           PUSH    AX                ;Save the registers
  364.           PUSH    BX
  365.           PUSH    CX
  366.           PUSH    DX
  367.           MOV     AH,8              ;Get the current character attribute
  368.           MOV     BH,VID_PAGE
  369.           INT     10H
  370.           CALL    WHERE_ARE_WE
  371.           PUSH    DX                ;save it
  372.           MOV     BH,AH             ;Transfer the attribute to BH for next call
  373.           MOV     AH,6              ;Otherwise scroll ??? lines
  374.           MOV     AL,0              ;clear line
  375.           MOV     CX,DX
  376.           MOV     DL,_abotx
  377.           INT     10H               ;And do it.......
  378.           MOV     AH,2
  379.           MOV     BH,VID_PAGE
  380.           POP     DX
  381.           INT     10H               ;restore position
  382.           POP     DX                ;Restore the stack like it was
  383.           POP     CX
  384.           POP     BX
  385.           POP     AX
  386.           RET
  387.  
  388. ANSI_PRNT ENDS
  389.           END
  390.